/* Copyright (c) 2009 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jessies.blogbaboon;

import com.google.gdata.data.blogger.*;
import java.util.*;
import javax.swing.table.*;

public class PostTableModel extends AbstractTableModel {
  private List<PostEntry> posts = Collections.emptyList();
  
  public void setPosts(List<PostEntry> posts) {
    this.posts = posts;
    fireTableDataChanged();
  }
  
  public PostEntry getPost(int i) {
    return posts.get(i);
  }
  
  public int getColumnCount() {
    return 2;
  }
  
  public int getRowCount() {
    return posts.size();
  }
  
  @Override public String getColumnName(int col) {
    return (col == 0) ? "Date" : "Title";
  }
  
  public Object getValueAt(int row, int col) {
    final PostEntry post = getPost(row);
    if (col == 0) {
      final String date = post.getUpdated().toUiString();
      return date;
    } else {
      return BlogUtils.displayableTitle(post);
    }
  }
}
